//--------------------------------------------------------------
//
// Qizhi Zhang 
// ezhung@gmail.com
// http://www.moorwind.com
//
//--------------------------------------------------------------
package reader.controller
{
	import flash.data.EncryptedLocalStore;
	import flash.net.registerClassAlias;
	import flash.utils.ByteArray;
	
	import org.puremvc.as3.multicore.interfaces.ICommand;
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.patterns.command.SimpleCommand;
	
	import reader.ApplicationFacade;
	import reader.model.vo.BlogDraftVO;

	public class ReadAutoSaveCommand extends SimpleCommand implements ICommand
	{
		//////////////////////////////////////////////////////////////////////////////
		//methods
		
		override public function execute(notification:INotification):void
		{
			registerClassAlias(BlogDraftVO.BLOG_DRAFT_ALIAS, BlogDraftVO);
			var draftBytes:ByteArray = EncryptedLocalStore.getItem(BlogDraftVO.BLOG_DRAFT_ALIAS);
			var blogDraftVO:BlogDraftVO
			if(draftBytes)
			{
				blogDraftVO = draftBytes.readObject() //as BlogDraftVO;
			}
			
			if(blogDraftVO)
			{
				sendNotification(ApplicationFacade.AUTOSAVE_READ_OK, blogDraftVO);
			}
			else
			{
				sendNotification(ApplicationFacade.AUTOSAVE_READ_NULL);
			}
		}
		
	}
}